package com.wages.project.system.dingding.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.wages.framework.aspectj.lang.annotation.Log;
import com.wages.framework.aspectj.lang.enums.BusinessType;
import com.wages.project.system.dingding.domain.Dingding;
import com.wages.project.system.dingding.service.IDingdingService;
import com.wages.framework.web.controller.BaseController;
import com.wages.framework.web.domain.AjaxResult;
import com.wages.common.utils.poi.ExcelUtil;
import com.wages.framework.web.page.TableDataInfo;

/**
 * 考勤Controller
 *
 * @author wages
 * @date 2021-03-18
 */
@Controller
@RequestMapping("/system/dingding")
public class DingdingController extends BaseController
{
    private String prefix = "system/dingding";

    @Autowired
    private IDingdingService dingdingService;

    @RequiresPermissions("system:dingding:view")
    @GetMapping()
    public String dingding()
    {
        return prefix + "/dingding";
    }

    /**
     * 查询考勤列表
     */
    @RequiresPermissions("system:dingding:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Dingding dingding)
    {
        startPage();
        List<Dingding> list = dingdingService.selectDingdingList(dingding);
        return getDataTable(list);
    }

    /**
     * 导出考勤列表
     */
    @RequiresPermissions("system:dingding:export")
    @Log(title = "考勤", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Dingding dingding)
    {
        List<Dingding> list = dingdingService.selectDingdingList(dingding);
        ExcelUtil<Dingding> util = new ExcelUtil<Dingding>(Dingding.class);
        return util.exportExcel(list, "dingding");
    }

    /**
     * 新增考勤
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存考勤
     */
    @RequiresPermissions("system:dingding:add")
    @Log(title = "考勤", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Dingding dingding)
    {
        return toAjax(dingdingService.insertDingding(dingding));
    }

    /**
     * 修改考勤
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Dingding dingding = dingdingService.selectDingdingById(id);
        mmap.put("dingding", dingding);
        return prefix + "/edit";
    }

    /**
     * 修改保存考勤
     */
    @RequiresPermissions("system:dingding:edit")
    @Log(title = "考勤", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Dingding dingding)
    {
        return toAjax(dingdingService.updateDingding(dingding));
    }

    /**
     * 删除考勤
     */
    @RequiresPermissions("system:dingding:remove")
    @Log(title = "考勤", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(dingdingService.deleteDingdingByIds(ids));
    }
}
